package ding.blog.service;

import com.example.myblog.entity.Comment;
import com.example.myblog.dao.CommentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentService {

    private final CommentRepository commentRepository;

    @Autowired
    public CommentService(CommentRepository commentRepository) {
        this.commentRepository = commentRepository;
    }

    // 保存评论
    public Comment saveComment(Comment comment) {
        return commentRepository.save(comment);
    }

    // 根据ID获取评论
    public Comment getCommentById(Long id) {
        return commentRepository.findById(id).orElse(null);
    }

    // 获取所有评论
    public List<Comment> getAllComments() {
        return commentRepository.findAll();
    }
}